import { Component, OnInit, Input } from '@angular/core'
import { Widget } from '../../model'
import { JsonApiService } from '../../../../core/api/json-api.service'


@Component({
  selector: 'api-invoke',
  templateUrl: './api-invoke.html',
  styleUrls: ['./api-invoke.css']
})
// API 接口调用
export class ApiInvoke implements OnInit, Widget {
  @Input() componentData: any
  // @Input() auth = true

  beforeYesterdayData = {
    data: '',
    size: ''
  }
  yesterdayData = {
    data: '',
    size: ''
  }
  todayData = {
    data: '',
    size: ''
  }

  loading = false

  constructor(private jsonApiService: JsonApiService) { }
  ngOnInit() {
    this.initData()
  }

  //当天总流量
  initData() {
    this.loading = true
    this.jsonApiService.http('control/station/api/invoke/apiInterfaceInvoke.html', null, false).subscribe(data => {
      this.loading = false
      if (data.success) {
        let temData = data.data;
        this.beforeYesterdayData = common.numberFormat(temData[0]);
        this.yesterdayData = common.numberFormat(temData[1]);
        this.todayData = common.numberFormat(temData[2]);
      } else {
        this.jsonApiService.message(data.message);
      }
    })
  }
}
